package com.huobao.yunying.activitys_hehuoren;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.activitys_store.Act_Store;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class Act_Dailipin_Liuyan_detail extends HuobaoBaseActivity {

	/**
	 * 留言id
	 */
	private String id;

	private TextView tv_name;
	private TextView tv_storename;
	private TextView tv_theme;
	private TextView tv_lianxi_name;
	private TextView tv_tel;
	private TextView tv_qq;
	private TextView tv_address;
	private TextView tv_content;
	private TextView tv_time;

	@Override
	protected int getContentView() {
		return R.layout.layout_liuyan_detail;
	}

	@Override
	protected String getTitleText() {
		return "意向详情";
	}

	@Override
	protected void init() {
		id = getIntent().getStringExtra("id");
		initView();
		getDetail();
	}

	private void initView() {
		tv_name = (TextView) findViewById(R.id.tv_name);
		tv_storename = (TextView) findViewById(R.id.tv_storename);
		tv_theme = (TextView) findViewById(R.id.tv_theme);
		tv_lianxi_name = (TextView) findViewById(R.id.tv_lianxi_name);
		tv_tel = (TextView) findViewById(R.id.tv_tel);
		tv_qq = (TextView) findViewById(R.id.tv_qq);
		tv_address = (TextView) findViewById(R.id.tv_address);
		tv_content = (TextView) findViewById(R.id.tv_content);
		tv_time = (TextView) findViewById(R.id.tv_time);

	}
	
	private void getDetail() {
		Map<String, String> map = HttpUtil.getParams("app", "partner", "act", "agents_show", "id", id);
		Http.getInstant().sendRequest(context, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				jsonObject = jsonObject.getJSONObject("retval");
				JSONObject agent_info = jsonObject.getJSONObject("agent_info");
				final JSONObject store = jsonObject.getJSONObject("store");
				final JSONObject goods_info = jsonObject.getJSONObject("goods_info");
				tv_name.setText(goods_info.getString("goods_name"));
//				tv_name.setOnClickListener(new OnClickListener() {
//					
//					@Override
//					public void onClick(View v) {
//						Intent intent = new Intent(context, Act_Detail.class);
//						intent.putExtra("id", goods_info.getString("goods_id"));
//						startActivity(intent);
//						SkipUtils.seeDetail(context, goods_info.getString("goods_id"), goods_info.getString("default_image"));
//					}
//				});

				tv_storename.setText(store.getString("store_name"));
				tv_storename.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						Intent intent = new Intent(context, Act_Store.class);
						intent.putExtra("id", store.getString("store_id"));
						startActivity(intent);
					}
				});
				tv_theme.setText(agent_info.getString("title"));
				tv_lianxi_name.setText(agent_info.getString("name"));
				tv_tel.setText(agent_info.getString("mobile"));
				tv_qq.setText(agent_info.getString("qqnum"));
				tv_address.setText(agent_info.getString("address"));
				tv_content.setText(agent_info.getString("content"));
				String time = agent_info.getString("add_time");
				if(time == null || time.equals("") || time.equals("null")){
					time = "";
				}else{
					try {
						long t = Long.parseLong(time) * 1000;
						time = new SimpleDateFormat("yyyy-MM-dd").format(new Date(t));
					} catch (Exception e) {
					}
				}
				tv_time.setText(time);
			}

			@Override
			public void onHttpError(String error) {

			}
		});
	}
}
